package com.wencai.util;

import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * @author wangpan
 * @date 2023/4/16
 */
public class ExcelListener extends AnalysisEventListener {

    private List<Object> list = new ArrayList<>();

    private int sheetNo = 0;


    @Override
    public void invokeHeadMap(Map headMap, AnalysisContext context) {
        list.add(headMap);
    }

    @Override
    public void invoke(Object data, AnalysisContext context) {
        int currentSheetNo = context.readSheetHolder().getSheetNo();
        if(currentSheetNo != sheetNo){
            list = new ArrayList<>();
            sheetNo = currentSheetNo;
        }
        list.add(data);
    }

    @Override
    public void doAfterAllAnalysed(AnalysisContext context) {

    }

    public List<Object> getList(){
        return list;
    }
}
